layui.use(['form', 'layedit', 'laydate','jquery'], function(){
    var form = layui.form
        ,layer = layui.layer
        ,layedit = layui.layedit
        ,laydate = layui.laydate
        ,$ = layui.jquery;


    //日期
    laydate.render({
        elem: '#date'
    });
    laydate.render({
        elem: '#date1'
    });

    //创建一个编辑器
    // var editIndex = layedit.build('LAY_demo_editor');

    //自定义验证规则
    form.verify({
        // title: function(value){
        //     if(value.length < 5){
        //         return '标题至少得5个字符啊';
        //     }
        // }
        username:[/^[a-zA-Z0-9_-]{4,16}$/,'用户名4-16位字母或数字']
        ,pass: [/(.+){6,12}$/, '密码必须6到12位']
        // ,content: function(value){
        //     layedit.sync(editIndex);
        // }
    });

    form.on('submit(login)', function(data){
        // var index = layer.msg('正在登录，请稍候',{icon: 16,time:20000,shade:0.8});
        // alert(data);
        $.ajax({
            type: "post",
            url: "../user/login.do",
            contentType: "application/json",
            async: false,
            data: JSON.stringify(data.field),
            success: function (data) {
                // layer.close(index);
                console.log(data);
                if (data.resultCode == 10000) {
                    console.log(data);
                    location.href =  "../user/index.do";
                } else {
                    top.layer.msg(data.msg, {icon: 2});
                }
            },
        });
    });





});